﻿using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

/// <summary>
/// 关卡选择按钮
/// </summary>
[RequireComponent(typeof(Button))]
public class LevelSelectBtn : MonoBehaviour
{
    // 关卡名称
    public int levelName = 1;
    public Text buttonNum;

    private void Start()
    {
        if (!buttonNum)
            buttonNum = transform.Find("Num").GetComponent<Text>();
        if (levelName != 11)
            buttonNum.text = levelName.ToString();
        // 监听事件
        GetComponent<Button>().onClick.AddListener(LoadSelectScene);
    }

    /// <summary>
    /// 加载选择的关卡
    /// </summary>
    public void LoadSelectScene()
    {
        AudioManager.Instance.PlayButtonSound();
        // 设置关卡数据
        PlayerPrefs.SetInt("Current_Level", levelName);
        MenuUIManager.Instance.ShowToturial();
    }
}
